Allocators

Lifetimes Hierarchy

  • Permanent Allocation :

    • Memory that is never freed until the end of the program. This memory is persistent during the program lifetime.

  • Transient Allocation :

    • Memory that has a cycle-based lifetime. This memory only persists for the β€œcycle” and is freed at the end of this cycle. An example of a cycle could be a frame within a graphical program (e.g. a game) or an update loop.

  • Scratch/Temporary Allocation :

    • Short-lived, quick memory that you just want to allocate and forget about. A common case for this is when generating a string and outputting it to a log.

Types of Allocators

Where to allocate

Algorithms for searching for free blocks
  • First Fit.

  • Next Fit.

    • Optimization from First Fit, but increases fragmentation, apparently.

  • Best Fit.

Coalescing ("Growing together, fusing")

  • When we have two free blocks next to each other, merge them together into one large block.

Strategies